
# apt update if more than 1 day
# since last apt update
apt_update() {
	local last_update=$(stat -c %Y /var/cache/apt/pkgcache.bin)
	local now=$(date +%s)
	local diff=$((now - last_update))
	if [ $diff -gt 86400 ]; then
		sudo apt update
	fi
}

apt_ensure() {
	local apt_package_name=${1:?"package name is required"}
	if ! dpkg -s $apt_package_name > /dev/null; then
		apt_update
		sudo apt install -y $apt_package_name
	fi
}
